package com.asia5b.a5mall.order.adapter

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.widget.TextView
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.model.shop.OrderParceExpressBean
import com.asia5b.a5mall.middleware.model.shop.OrderParcelFeeBean


import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.WImageLoader
import com.asia5b.a5mall.order.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/3/16.
 */
class ParcelDetailAdapter(list: ArrayList<OrderParceExpressBean>) :
        BaseQuickAdapter<OrderParceExpressBean, BaseViewHolder>(R.layout.item_parceldetail_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: OrderParceExpressBean) {
        helper.setText(R.id.tv_parcel_ordersn, item.express_sn)
        if (!item.goods_list.isNullOrEmpty()) {
            val goodsRecyclerView = helper.getView<RecyclerView>(R.id.rv_parcel_goods)
            val goodsAdapter = ParcelGoodsAdapter(item.goods_list!!)
            goodsRecyclerView.run {
                layoutManager = LinearLayoutManager(context)!!
                adapter = goodsAdapter
            }
        }
        if (!item.fee_list.isNullOrEmpty()) {
            val feeRecyclerView = helper.getView<RecyclerView>(R.id.rv_parcel_parcellist)
            val feeAdapter = ParcelFeeAdapter(item.fee_list!!)
            feeRecyclerView.run {
                layoutManager = LinearLayoutManager(context)!!
                adapter = feeAdapter
            }
        }
    }
}

class ParcelGoodsAdapter(list: ArrayList<AbsGoodsModel>) :
        BaseQuickAdapter<AbsGoodsModel, BaseViewHolder>(R.layout.goodsitem_parceldetail, list) {
    override fun convert(helper: BaseViewHolder, item: AbsGoodsModel) {
        WImageLoader.displayRoundImage(item.absGoodsImageUrl, helper.getView(R.id.iv_goods_img),5)
        helper.setText(R.id.tv_goods_name, item.absGoodsName)

        val tv_goods_price = helper.getView<TextView>(R.id.tv_goods_price)
        //商品总价格
        CurrencyPriceBuilder3().run{
            textView=tv_goods_price
            price=item.absGoodsOriginalPrice
            priceList=item.absGoodsOriginalPriceList
            build()
        }
    }
}

class ParcelFeeAdapter(list: ArrayList<OrderParcelFeeBean>) :
        BaseQuickAdapter<OrderParcelFeeBean, BaseViewHolder>(R.layout.item_parcel_parcel_adapter, list) {
    override fun convert(helper: BaseViewHolder, item: OrderParcelFeeBean) {
        helper.setText(R.id.tv_parcel_num, String.format(ResString.get(R.string.包裹_数),"${helper.layoutPosition + 1}"))
        helper.setText(R.id.tv_parcel_weight, "${item.net_weight} kg")
//        helper.setText(R.id.tv_parcel_vol, "${item.volume_weight} m³")
        helper.setText(R.id.tv_parcel_vol, "${item.size}")
    }
}